package com.ruoyi.bigbase.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.bigbase.domain.IdentityVerification;
import com.ruoyi.bigbase.domain.Integral;
import com.ruoyi.bigbase.mapper.IntegralMapper;
import com.ruoyi.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.bigbase.mapper.IntegralDetailsMapper;
import com.ruoyi.bigbase.domain.IntegralDetails;
import com.ruoyi.bigbase.service.IIntegralDetailsService;

/**
 * 积分明细Service业务层处理
 * 
 * @author bigbase
 * @date 2025-05-15
 */
@Service
public class IntegralDetailsServiceImpl implements IIntegralDetailsService 
{
    @Autowired
    private IntegralDetailsMapper integralDetailsMapper;

    @Autowired
    private IntegralMapper integralMapper;

    /**
     * 查询积分明细
     * 
     * @param id 积分明细主键
     * @return 积分明细
     */
    @Override
    public IntegralDetails selectIntegralDetailsById(Integer id)
    {
        return integralDetailsMapper.selectIntegralDetailsById(id);
    }

    /**
     * 查询积分明细列表
     * 
     * @param integralDetails 积分明细
     * @return 积分明细
     */
    @Override
    public List<IntegralDetails> selectIntegralDetailsList(IntegralDetails integralDetails)
    {
        return integralDetailsMapper.selectIntegralDetailsList(integralDetails);
    }

    /**
     * 新增积分明细
     * 
     * @param integralDetails 积分明细
     * @return 结果
     */
    @Override
    public int insertIntegralDetails(IntegralDetails integralDetails)
    {
        Integer preScore = integralMapper.getIntegralByUserId(integralDetails.getUserId());
        Integral integral = new Integral();
        integral.setUserId(integralDetails.getUserId());
        integral.setIntegral(preScore+integralDetails.getScore());
        integral.setLastUpdateTime(DateUtils.getNowDate());
        integralMapper.updateIntegralByUserId(integral);
        integralDetails.setBalance(integral.getIntegral());// 设置余额
        integralDetails.setTime(DateUtils.getNowDate());// 设置创建时间

        return integralDetailsMapper.insertIntegralDetails(integralDetails);
    }

    /**
     * 修改积分明细
     * 
     * @param integralDetails 积分明细
     * @return 结果
     */
    @Override
    public int updateIntegralDetails(IntegralDetails integralDetails)
    {
        return integralDetailsMapper.updateIntegralDetails(integralDetails);
    }

    /**
     * 批量删除积分明细
     * 
     * @param ids 需要删除的积分明细主键
     * @return 结果
     */
    @Override
    public int deleteIntegralDetailsByIds(Integer[] ids)
    {
        return integralDetailsMapper.deleteIntegralDetailsByIds(ids);
    }

    /**
     * 删除积分明细信息
     * 
     * @param id 积分明细主键
     * @return 结果
     */
    @Override
    public int deleteIntegralDetailsById(Integer id)
    {
        return integralDetailsMapper.deleteIntegralDetailsById(id);
    }

    @Override
    public Date getTimeByUserId(Integer userId) {
        return integralDetailsMapper.getTimeByUserId(userId);
    }

}
